package order

import (
	"strings"
	"sync"
	"time"
	"yan-feeorder/common"
	log "ycx-glog"
)

var baseNunber uint64 = 0
var mu sync.Mutex

func GetOrderSN() string {
	defer mu.Unlock()
	mu.Lock()
	tmStr := time.Now().Format("060102150405.999999") + "000000"
	str := strings.Replace(tmStr, ".", "", -1)
	if len(str) < 16 {
		log.Infoln(str)
		return tmStr
	}
	str = str[:16]
	rx := uint64(common.ValueToInt(str, 0))
	if rx > baseNunber {
		baseNunber = rx
		return str
	}
	baseNunber++
	str = common.ValueToString(baseNunber, "")
	if len(str) != 16 {
		return tmStr
	}
	return str
}
